package com.platform.modules.mall.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.common.utils.Query;
import com.platform.modules.mall.dao.MallCardShopsDao;
import com.platform.modules.mall.entity.MallCardShopsEntity;
import com.platform.modules.mall.service.MallCardShopsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 卡卷店铺关联表Service实现类
 *
 * @author
 * @date 2020-08-14 09:57:01
 */
@Service("mallCardShopsService")
public class MallCardShopsServiceImpl extends ServiceImpl<MallCardShopsDao, MallCardShopsEntity> implements MallCardShopsService {

    @Override
    public List<MallCardShopsEntity> queryAll(Map<String, Object> params) {
        return baseMapper.queryAll(params);
    }

    @Override
    public Page queryPage(Map<String, Object> params) {
        //排序
        params.put("sidx", "T.ID");
        params.put("asc", false);
        Page<MallCardShopsEntity> page = new Query<MallCardShopsEntity>(params).getPage();
        return page.setRecords(baseMapper.selectMallCardShopsPage(page, params));
    }

    @Override
    public Page queryPageUnionCard(Map<String, Object> params) {
        //排序
        params.put("sidx", "T.ID");
        params.put("asc", false);
        Page<Map<String,Object>> page = new Query<Map<String,Object>>(params).getPage();
        return page.setRecords(baseMapper.queryPageUnionCard(page, params));
    }

    @Override
    public List<Map<String, Object>> queryPageUnionShops(Map<String, Object> params) {
        return baseMapper.queryPageUnionShops(params);
    }

    @Override
    public boolean add(MallCardShopsEntity mallCardShops) {
        return this.save(mallCardShops);
    }

    @Override
    public boolean update(MallCardShopsEntity mallCardShops) {
        return this.updateById(mallCardShops);
    }

    @Override
    public boolean delete(String id) {
        return this.removeById(id);
    }

    @Override
    public boolean deleteByCardId(String id) {
        Map map = new HashMap(3);
        map.put("goods_id", id);
        return this.removeByMap(map);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatch(String[] ids) {
        return this.removeByIds(Arrays.asList(ids));
    }
}
